// --------------------------------------------------------------------------------------------------------------------
// <copyright file="DC.DictionaryService.cs" company="Open Trader">
//   Copyright (c) David Denis (david.denis@systemathics.com)
// </copyright>
// <summary>
//   |  Open Trader - The Open Source Systematic Trading Platform
//   |
//   |  This program is free software: you can redistribute it and/or modify
//   |  it under the terms of the GNU General Public License as published by
//   |  the Free Software Foundation, either version 2 of the License, or
//   |  (at your option) any later version.
//   |
//   |  This program is distributed in the hope that it will be useful,
//   |  but WITHOUT ANY WARRANTY; without even the implied warranty of
//   |  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//   |  GNU General Public License for more details.
//   |
//   |  You should have received a copy of the GNU General Public License
//   |  along with this program.  If not, see http://www.gnu.org/licenses
//   |
//   |  Up to date informations about Open Trader can be found at :
//   |    http://opentrader.org
//   |    http://opentrader.codeplex.com
//   |
//   |  For professional services, please visit us at :
//   |    http://www.systemathics.com
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace Org.OpenTrader.Framework.Forge.DataCache
{
    #region Using Directives

    using System;
    using System.Collections.Generic;

    using Org.OpenTrader.Framework.Forge.Entities;
    using Org.OpenTrader.Framework.Forge.Enums;

    #endregion

    /// <summary>
    /// The dao.
    /// </summary>
    public partial class DC
    {
        #region Constants and Fields

        /// <summary>
        /// The currency prices.
        /// </summary>
        private IDictionary<ECurrency, double> currencyPrices;

        /// <summary>
        /// The dictionary currency.
        /// </summary>
        private ECurrency dictionaryCurrency;

        #endregion

        #region Public Methods

        /// <summary>
        /// The create dictionary.
        /// </summary>
        /// <param name="dictionaryId">
        /// The dictionaryId.
        /// </param>
        /// <param name="currency">
        /// The currency.
        /// </param>
        /// <returns>
        /// The create dictionary.
        /// </returns>
        public bool CreateDictionary(Guid dictionaryId, ECurrency currency)
        {
            return DBDictionaryServiceHelpers.CreateDictionary(dictionaryId, currency);
        }

        /// <summary>
        /// The exists dictionary.
        /// </summary>
        /// <param name="dictionaryId">
        /// The dictionaryId.
        /// </param>
        /// <returns>
        /// The exists dictionary.
        /// </returns>
        public bool ExistsDictionary(Guid dictionaryId)
        {
            return DBDictionaryServiceHelpers.ExistsDictionary(dictionaryId);
        }

        /// <summary>
        /// The get currency prices.
        /// </summary>
        /// <param name="dictionaryId">
        /// The dictionaryId.
        /// </param>
        /// <returns>
        /// </returns>
        public IDictionary<ECurrency, double> GetCurrencyPrices(Guid dictionaryId)
        {
            if (this.currencyPrices == null)
            {
                var status = DBDictionaryServiceHelpers.GetCurrencyPrices(dictionaryId);
                if (status)
                {
                    this.currencyPrices = status.NestedObject;
                }
                else
                {
                    this.currencyPrices = new Dictionary<ECurrency, double>();
                }
            }

            return this.currencyPrices;
        }

        /// <summary>
        /// The get domestic currency.
        /// </summary>
        /// <param name="dictionaryId">
        /// The dictionaryId.
        /// </param>
        /// <returns>
        /// </returns>
        public ECurrency GetDomesticCurrency(Guid dictionaryId)
        {
            if (this.dictionaryCurrency == 0)
            {
                var status = DBDictionaryServiceHelpers.GetDomesticCurrency(dictionaryId);
                if (status)
                {
                    this.dictionaryCurrency = status.NestedObject;
                }
                else
                {
                    this.dictionaryCurrency = ECurrency.EUR;
                }
            }

            return this.dictionaryCurrency;
        }

        #endregion
    }
}